// Author: Domien Nowicki, Bjorn Schobben


#ifndef GLRENDERERWIDGETIMPL_H
#define GLRENDERERWIDGETIMPL_H

#include <QGLWidget>
#include "Pixel.h"
#include "Vector.h"
#include "Poly.h"
#include <list>


class GLRendererWidgetImpl : public QGLWidget
{
    Q_OBJECT

public:
    GLRendererWidgetImpl(QWidget *parent = 0, const QGLWidget * shareWidget = 0, Qt::WFlags flags = 0);
    virtual ~GLRendererWidgetImpl();

	void SetPixel(unsigned int x, unsigned int y, const Pixel& pixel);
	Pixel GetPixel(unsigned int x, unsigned int y) const;
	unsigned int GetHeight() const;
	unsigned int GetWidth() const;

	void Update();
	void DrawPolygon(const Poly& poly);

protected:
    void initializeGL();
    void paintGL();
    void resizeGL(int width, int height);

private:
	void Start2D();
	void End2D();

	unsigned int nextpow2(unsigned int n);

	void SetTextureSize(unsigned int width, unsigned int height);
	void FreeTexture();
	void SetTexture();

	std::list<Poly> updatePolygons;
	std::list<Poly> currentPolygons;

	GLuint textureId;
	unsigned int textureHeight, textureWidth, textureHeightPow2, textureWidthPow2;
	unsigned int lastTextureHeight, lastTextureWidth;
	unsigned char *textureData;
};

#endif // GLRENDERERWIDGETIMPL_H
